package com.kehutong.basic.annex.admin;

import org.coraframework.inject.Inject;
import org.coraframework.json.JSONObject;
import org.coraframework.mvc.MvcAction;
import org.coraframework.mvc.http.Bean;
import org.coraframework.mvc.http.ReqMapping;
import org.coraframework.util.Objects;
import com.kehutong.basic.annex.entity.BasicAnnex;
import com.kehutong.basic.annex.service.BasicAnnexService;
import com.kehutong.common.errcode.Result;
import com.kehutong.common.util.Token;

/**
 * 公用附件
 */
@MvcAction
@ReqMapping("/admin/basic/annex")
public class BasicAnnexController {

    @Inject
    private BasicAnnexService annexService;

    @ReqMapping("/list/page")
    public Object list(JSONObject jsonObject){
        return annexService.listPage(jsonObject);
    }

    @ReqMapping("/save")
    public Object save(Token token, JSONObject jsonObject){

        if (!checkLogin(token)) {
            return org.coraframework.mvc.http.result.Result.error(0, "请先登录");
        }

        return annexService.saveAnnex(token, jsonObject);
    }

    @ReqMapping("/del")
    public Object del(BasicAnnex annex){
        return annexService.del(annex);
    }

    @ReqMapping("/batch/del")
    public Object batchDel(JSONObject jsonObject){
        return annexService.batchDel(jsonObject);
    }


    private boolean checkLogin(Token token){
        if (Objects.isNull(token)) {
            return false;
        }

        if (Objects.isEmpty(token.getUuid()) && Objects.isEmpty(token.getUsername())) {
            return false;
        } else {
            return true;
        }
    }

}
